﻿Imports NewHeaderSystems.Archive.Data

Public Class Home
    Inherits PageTemplate

    Private Sub Home_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Title = "Welcome to Trade Confirms Archive"
        Description = "Select a task from the list below."
        PageIcon = My.Resources.Folder_Secure
    End Sub

    Private Sub lnkSearch_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkSearch.LinkClicked
        GoToPage(FormTypes.Search)
    End Sub

    Private Sub lnkProcessUnassigned_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkProcessUnassigned.LinkClicked        
        GoToPage(FormTypes.FinishArchiving)
    End Sub

    Private Sub lnkSystemSettings_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkSystemSettings.LinkClicked
        GoToPage(FormTypes.Administration)
    End Sub

    Private Sub lnkStartArchiving_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkStartArchiving.LinkClicked
        GoToPage(FormTypes.StartArchiving)
    End Sub

    Private Sub LoadSettings()
        Dim lastArchived As Date, totalCompleted As Integer, unassignedCount As Integer

        DataScript.GetSystemStatistics(lastArchived, totalCompleted, unassignedCount)

        If (lastArchived = Date.MinValue) Then
            lblLastCompleted.Text = "Never"
        Else
            lblLastCompleted.Text = lastArchived.ToString("G")
        End If

        lblTotalCompleted.Text = totalCompleted.ToString()
        lblUnassigned.Text = unassignedCount.ToString()

    End Sub

    Private Sub Home_PageEnter(ByVal sender As System.Object, ByVal e As Microsoft.Samples.Windows.Forms.Navigation.PageEventArgs) Handles MyBase.PageEnter
        Dim configurationHelper As New ConfigurationHelper
        If Not configurationHelper.TestConnection() Then
            Dim setupDatabaseForm As New SetupDatabase(True)
            Dim result As DialogResult = setupDatabaseForm.ShowDialog()
            If result = DialogResult.Cancel Then
                End 'No valid database to use let's exit.
            Else
                GoToPage(FormTypes.SystemSettings) 'Let the user configure the settings.
            End If
        Else
            DataScript.CheckAndUpgradeDatabase() 'Lets bring the database up-to-date if there are any new changes.
        End If
        LoadSettings()
    End Sub
End Class
